package com.cloud.demo.controller;

import com.cloud.demo.pojo.User;
import com.cloud.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

//@RestController
//@RequestMapping("/${version}/user")
//@Api(value = "UserController", description = "UserController", produces = MediaType.APPLICATION_JSON_VALUE)
//public class UserController {
//    @Autowired
//    private UserService userService;
//
//    //    @RequestMapping("/login")
//    @PostMapping("/login")
//    @ApiOperation(value = "登录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiImplicitParam(name = "user", value = "用户登录信息", dataType = "user")
//    public User login(@ModelAttribute User user) {
//        return userService.getUserByName(user.getUsername());
//    }
//
//    //    @RequestMapping("/{userId}")
//    @GetMapping("/{userId}")
//    @ApiOperation(value = "通过用户id查询用户", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int", required = true, paramType = "path")
//    public User getUserById(@PathVariable("userId") Integer userId) {
//        return userService.getUserById(userId);
//    }
//}


@RestController
public class UserController {
    @Autowired
    private UserService userService;

    //    @RequestMapping("/login")
    @PostMapping("/login")
    @ApiOperation(value = "登录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "user", value = "用户登录信息", dataType = "user")
    public User login(@ModelAttribute User user) {
        return userService.getUserByName(user.getUsername());
    }

    //    @RequestMapping("/{userId}")
    @GetMapping("/{userId}")
    @ApiOperation(value = "通过用户id查询用户", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int", required = true, paramType = "path")
    public User getUserById(@PathVariable("userId") Integer userId) {
        return userService.getUserById(userId);
    }
}
